package com.doge.service.admin.feedback;

import com.alibaba.druid.util.StringUtils;
import com.doge.bean.base.BaseData;
import com.doge.bean.base.BaseParam;
import com.doge.bean.pojo.feedback.Feedback;
import com.doge.bean.pojo.feedback.FeedbackExample;
import com.doge.mapper.FeedbackMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project2-wechat-mall
 * @description: 用户反馈
 * @author: zhu lei
 * @create: 2021-11-30 16:55
 **/
@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    FeedbackMapper feedbackMapper;
    @Override
    public BaseData feedbackList(Integer id, String username, BaseParam baseParam) {
        PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
        FeedbackExample feedbackExample = new FeedbackExample();
        FeedbackExample.Criteria criteria = feedbackExample.createCriteria();
        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        if (!StringUtils.isEmpty(username)) {
            criteria.andUsernameLike(username);
        }
        feedbackExample.setOrderByClause(baseParam.getSort() + " " + baseParam.getOrder());
        List<Feedback> feedbacks = feedbackMapper.selectByExample(feedbackExample);
        PageInfo<Feedback> feedbackPageInfo = new PageInfo<>(feedbacks);
        long total = feedbackPageInfo.getTotal();
        return BaseData.list(feedbacks,total);
    }
}